#!/bin/bash

# source $PWD/conf.properties
baseDir=/opt/programs

echo ""
echo "-----------------------------------"
echo "安装 elasticsearch"
elasticsearchDir=$baseDir/elasticsearch
mkdir -p $elasticsearchDir/data && chmod 777 $elasticsearchDir/data
echo "安装目录：$elasticsearchDir"
docker run --privileged -d --restart=always \
    --network mynet --network-alias elasticsearch-net \
    --log-driver json-file \
    --log-opt max-file=1 \
    --log-opt max-size=100m \
    -m 1GB \
    -p 9200:9200 \
    -p 9300:9300 \
    -v /etc/localtime:/etc/localtime \
    -v /etc/timezone:/etc/timezone \
    -v $elasticsearchDir/data:/usr/share/elasticsearch/data \
    -e "discovery.type=single-node" \
    -e "xpack.security.enabled=false" \
    -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
    -e "http.port=9200" \
    -e "http.max_content_length=10MB" \
    -e "http.cors.enabled=true" \
    -e "http.cors.allow-origin=\*" \
    -e "http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization" \
    -e "http.cors.allow-credentials=true" \
    -e "network.publish_host=localhost" \
    --name elasticsearch \
    elasticsearch:8.17.0


# -----------------------------------------

# echo "-----------------------------------"
# echo "安装 dejavu, elasticsearch的浏览器操作界面"
# docker run --privileged -d --restart=always \
#     --network znsxnet --network-alias hsrg-dejavu \
#     --log-driver json-file \
#     --log-opt max-file=1 \
#     --log-opt max-size=100m \
#     -p 1358:1358/tcp \
#     --name es-dejavu \
#     appbaseio/dejavu:3.8.3
